use std::error::Error;
use std::fs;

pub struct Config {
    pub mode: String,
    pub path: String,
}

impl Config {
    pub fn new(args: &[String]) -> Result<Config, &'static str> {
        if args.len() < 3 {
            return Err("not enough arguments");
        }

        let mode = args[1].clone();
        let path = args[2].clone();

        Ok(Config { mode, path })
    }
}


pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
    // let contents = fs::read_to_string(config.path)?;

    // println!("With text:\n{}", contents);
    let paths = fs::read_dir(config.path).unwrap();

    for path in paths {
        let p = path.unwrap().path().display().to_string();
        // println!("{}", p);
        if p!=".git/objects/pack" && p!=".git/objects/info" {
            let paths_x = fs::read_dir(p).unwrap();
            for path_x in paths_x {
                let p_x = path_x.unwrap().path().display().to_string();
                println!("{}", p_x); //object path


                let mut objects = p_x[13..15].to_string();
                objects += &p_x[16..];
                println!("{}", objects);


            }
        }
        
    }
    Ok(())
}